-
Notifications
You must be signed in to change notification settings - Fork 9.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix warning with torch.meshgrid #8090
base: dev
Are you sure you want to change the base?
Conversation
Hi @pallgeuer ,
|
Good point. This affects many packages (mmdetection, mmpose, mmclassification, etc). How to best deal with that? |
Since we do not want to increase the dependency on mmcv so fast, we can add a wrapper in mmcv first, then we can also copy the wrapper in mmdet and use that in mmcv if the mmcv version meets our demand, otherwise we can use that in mmdet. |
Where would be the appropriate file/location in mmcv and mmdet to add such wrappers? |
I have updated the PR with the same solution as was merged for mmpose: |
mmdet/utils/misc.py
Outdated
@@ -74,3 +76,14 @@ def update(cfg, src_str, dst_str): | |||
|
|||
update(cfg.data, cfg.data_root, dst_root) | |||
cfg.data_root = dst_root | |||
|
|||
|
|||
_torch_version_meshgrid_indexing = version.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the version comparison style in MMCV https://github.com/open-mmlab/mmcv/blob/235c0253ab8806a2a2ee6954b4258a95358497ac/mmcv/parallel/distributed.py#L40, it might be better to write the code as below:
from mmcv.utils import TORCH_VERSION, digit_version
if ('parrots' not in TORCH_VERSION
and digit_version(TORCH_VERSION) >= digit_version('1.10')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to find much information on the parrots version of PyTorch - what should it do in that case? Does the torch.meshgrid
method for parrots PyTorch support the indexing parameter or not and/or does it raise a warning?
I had a look and couldn't immediately identify what exactly digit_version
does differently. In what case would the result of a version comparison like I coded it and your proposal differ?
digit_version('1.10')
is not quite sufficient by the way, it does really need to be digit_version('1.10.0a0')
. My own PyTorch installation is exactly inbetween those two and it makes a difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't seem to find much information on the parrots version of PyTorch - what should it do in that case? Does the
torch.meshgrid
method for parrots PyTorch support the indexing parameter or not and/or does it raise a warning?I had a look and couldn't immediately identify what exactly
digit_version
does differently. In what case would the result of a version comparison like I coded it and your proposal differ?
digit_version('1.10')
is not quite sufficient by the way, it does really need to bedigit_version('1.10.0a0')
. My own PyTorch installation is exactly inbetween those two and it makes a difference.
It is an internal version that we support. You are right that digit_version does not do anything different, it is just a convention. Then how about using digit_version('1.10.0a0')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the PR
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## dev #8090 +/- ##
==========================================
- Coverage 64.69% 64.18% -0.52%
==========================================
Files 351 361 +10
Lines 28463 29537 +1074
Branches 4807 5020 +213
==========================================
+ Hits 18414 18958 +544
- Misses 9057 9575 +518
- Partials 992 1004 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi. @pallgeuer , _torch_version_meshgrid_indexing = (
'parrots' not in TORCH_VERSION
and digit_version(TORCH_VERSION) >= digit_version('1.10.0a0'))
def torch_meshgrid(*tensors):
"""A wrapper of torch.meshgrid to compat different PyTorch versions.
Since PyTorch 1.10.0a0, torch.meshgrid supports the arguments ``indexing``.
So we implement a wrapper here to avoid warning when using high-version PyTorch and avoid compatibility issues when using previous versions of PyTorch.
Args:
xxx: (add description here for each argument)
Return:
"""
if _torch_version_meshgrid_indexing:
return torch.meshgrid(*tensors, indexing='ij')
else:
return torch.meshgrid(*tensors) # Uses indexing='ij' by default The docstring should be completed following the google docstring guide. Thank you! |
I have updated the mmcv PR. |
Hi @pallgeuer , |
MMCV already supports torch_meshgrid wrapper since 1.6.0 https://github.com/open-mmlab/mmcv/releases/tag/v1.6.0. We can upgrade the minimum requirement of MMCV since this PR. |
Motivation
torch.meshgrid()
has started raising a warning when not called with an explicit indexing parameter:https://pytorch.org/docs/stable/generated/torch.meshgrid.html
gives
Modification
Provide
indexing='ij'
to all calls totorch.meshgrid
that don't already specifyindexing
.